package program;

import java.awt.Component;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

import stock.Company;

public class ChainingInference {

	void setInformation( JPanel responsePanel, ArrayList<Company> companies, final Company merval ){
		responsePanel.removeAll();
		responsePanel.setLayout(new BoxLayout(responsePanel, BoxLayout.Y_AXIS));
		
		String information = "";
		if ( companies.size() == 0 ){
			JLabel jl = new JLabel(" There are no ideal options according to the rules.");
			jl.setAlignmentX(Component.LEFT_ALIGNMENT);
			responsePanel.add(jl);
		}else{
			for (final Company c : companies){
				information = "  - "+c.getName();
				final JLabel jl = new JLabel(information);
				jl.setAlignmentX(Component.LEFT_ALIGNMENT);
				jl.setFont(GUIConstants.fontNormal);
				jl.setForeground(GUIConstants.companyNameColor);
				responsePanel.add(jl);
				jl.addMouseListener( new MouseListener() {
					
					@Override
					public void mouseReleased(MouseEvent arg0) {
						
					}
					
					@Override
					public void mousePressed(MouseEvent arg0) {
						
					}
					
					@Override
					public void mouseExited(MouseEvent arg0) {

						jl.setFont( GUIConstants.fontNormal ) ;
					}
					
					@Override
					public void mouseEntered(MouseEvent arg0) {

						jl.setFont( GUIConstants.fontSub ) ;
					}
					
					@Override
					public void mouseClicked(MouseEvent arg0) {
						launchCompanyInformation(c, merval);
					}
				}) ;
			}	
		}
		responsePanel.updateUI();
	}
	
	private void launchCompanyInformation(Company company, Company merval){
		CompanyInformationGUI.run(company, merval);
	}
	
}
